package com.thinkgem.jeesite.modules.magnetic.util;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author xlp
 * @date 2019/4/9
 * 地磁感应计算通过的车辆
 */
@Component
public class FieldMagneticUtil {

    @Autowired
    private TCPClient tcpClient;

    public void execute(){
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, 20,
                3, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5),
                new ThreadPoolExecutor.CallerRunsPolicy());

        poolExecutor.execute(tcpClient);
    }

    /**
     * 线程池执行的任务
     * @author hdpan
     */
    public static class ThreadPoolTask implements Runnable, Serializable {

        private static final long serialVersionUID = 0;

        //保存任务所需要的数据
        private Object threadPoolTaskData;

        ThreadPoolTask(Object tasks){
            this.threadPoolTaskData = tasks;
        }
        public void run(){
            //处理一个任务，这里的处理方式太简单了，仅仅是一个打印语句
            System.out.println("start .."+threadPoolTaskData);
            threadPoolTaskData = null;
        }
        public Object getTask(){
            return this.threadPoolTaskData;
        }
    }

}
